﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using SDT.Mobile.Models;
using SDT.Model;
using System.Linq.Dynamic;
using SDT.Mobile.Properties;
using SDT.Lib.Paging;
using SDT.Lib.Common;
using SDT.Lib.Helpers;
namespace SDT.Mobile.Controllers
{
    [RoleHelper(Roles = RoleSystem.Dictionary)]
    public class DemandController : Controller
    {
        //
        // GET: /Demand/
        SDTDataContext eDataContext = new SDTDataContext();
        public ActionResult Create(int ? id)
        {
            var de = new DemandCreateModel();
            //int cityid = Request["CityID"] !=null? Utils.ParseInt(Request["CityID"]):0;
            de.DedmandTypes = eDataContext.DemandTypes.ToList();
            de.DemandCategories = eDataContext.DemandCategories.ToList();
            de.Cities = eDataContext.Cities.ToList();
            de.Districts = eDataContext.Districts.Where(e => e.CityID.Equals(id)).ToList();
            Demand dema = new Demand();
            dema.DemandTypeID = Request["ddDemandType"] != null ? Utils.ParseInt(Request["ddDemandType"]) : 0;
            dema.CatID = Request["ddDemandCate"] != null ? Utils.ParseInt(Request["ddDemandCate"]) : 0;
            dema.CityID = Request["ddlCity"] != null ? Utils.ParseInt(Request["ddlCity"]) : 0;
            dema.DistrictID = Request["ddlDistrict"] != null ? Utils.ParseInt(Request["ddlDistrict"]) : 0;
            dema.Title = Request["title"];
            dema.Description = Request["content"];
            dema.ContactMobile = Request["mobile"];
            dema.AddDate = DateTime.Now;
             dema.PubYN = false;
            dema.HotYN = false;
            dema.VIPYN = false;
            // pro.AddBy = UserManager.GetUserId();
            if (dema.DemandTypeID > 0 && dema.CatID > 0 && dema.CityID > 0 && dema.DistrictID > 0 && dema.Title != "" && dema.Title != null && dema.Description != "" && dema.Description != null)
            {
                eDataContext.Demands.InsertOnSubmit(dema);
                eDataContext.SubmitChanges();
                return View("success");
            }
            else
            {
                return View(de);
            }
        }
        public ActionResult success()
        {
            return View();
        }
    }
}
